import java.util.*;

class Student implements Comparable<Student>{
    public String name;
    public  int age;
    public Student(String name,int age){
        this.name=name;
        this.age=age;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Student student = (Student) o;
        return age == student.age && Objects.equals(name, student.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, age);
    }

    @Override//这样写compareTo方法会固定
    public int compareTo(Student o) {
        return this.age-o.age;//大于返回正数
    }
}
//比较器
class NameComparator implements Comparator<Student>{
    @Override
    public int compare(Student o1, Student o2) {
        return o1.name.compareTo(o2.name);
    }
}
class AgeComparator implements Comparator<Student>{
    @Override
    public int compare(Student o1, Student o2) {
        return o1.age- o2.age;
    }
}
public class Test {

    public static void main1(String[] args) {
        TestHeap testHeap=new TestHeap();
        int[] arr={27,15,19,18,28,34,65,49,25,37};
        testHeap.initElem(arr);//初始化数组
        testHeap.creareHeap();//创建堆
        //testHeap.offer(80);
        testHeap.pop();
        System.out.println();
    }

    public static void main2(String[] args) {
        //创建堆
        PriorityQueue<Integer> priorityQueue=new PriorityQueue<>();
        //接口实现
        Queue<Integer> priorrtQueue1=new PriorityQueue<>();
        priorrtQueue1.offer(10);
        priorrtQueue1.offer(2);
        System.out.println(priorrtQueue1.poll());
    }
    //接口comparable
    public static void main4(String[] args) {
        Student student1=new Student("zhangsan",19);
        Student student2=new Student("zhangsan",19);
        System.out.println(student2.equals(student1));
        System.out.println(student2.compareTo(student1));
        NameComparator nameComparator1=new NameComparator();
        System.out.println(nameComparator1.compare(student1, student2));
    }
    //n个节点
    /*2^0,1,
    * 2^1,2,节点个数2^(i-1),i表示层数
    * 2^3,3，
    * */

    public static void main(String[] args) {
        TestHeap testHeap=new TestHeap();

        int[] arr={27,15,19,18,28,34,65,49,25,37};
        testHeap.initElem(arr);
        testHeap.creareHeap();
        testHeap.HeapSort();
        System.out.println();

    }

}
